<?php
/* tblCardDetails */
class tblCardDetails extends NocForm
	{
		protected $_ID                 = array();
		protected $_OrderHeader                 = array();
		protected $_Name                 = array();
		protected $_CardType                 = array();
		protected $_CardNumber                 = array();
		protected $_ExpiryMonth                 = array();
		protected $_ExpiryYear                 = array();
		protected $_StartMonth                 = array();
		protected $_StartYear                 = array();
		protected $_IssueNo                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_OrderHeader()
		{
				return  $this->_get_OrderHeaderValue();
		}

		private function _get_OrderHeaderValue()
		{
			if(isset($this->_OrderHeader['value']))
				return $this->_OrderHeader['value'];
			else
				return false;
		}

		public function get_Name()
		{
				return  $this->_get_NameValue();
		}

		private function _get_NameValue()
		{
			if(isset($this->_Name['value']))
				return $this->_Name['value'];
			else
				return false;
		}

		public function get_CardType()
		{
				return  $this->_get_CardTypeValue();
		}

		private function _get_CardTypeValue()
		{
			if(isset($this->_CardType['value']))
				return $this->_CardType['value'];
			else
				return false;
		}

		public function get_CardNumber()
		{
				return  $this->_get_CardNumberValue();
		}

		private function _get_CardNumberValue()
		{
			if(isset($this->_CardNumber['value']))
				return $this->_CardNumber['value'];
			else
				return false;
		}

		public function get_ExpiryMonth()
		{
				return  $this->_get_ExpiryMonthValue();
		}

		private function _get_ExpiryMonthValue()
		{
			if(isset($this->_ExpiryMonth['value']))
				return $this->_ExpiryMonth['value'];
			else
				return false;
		}

		public function get_ExpiryYear()
		{
				return  $this->_get_ExpiryYearValue();
		}

		private function _get_ExpiryYearValue()
		{
			if(isset($this->_ExpiryYear['value']))
				return $this->_ExpiryYear['value'];
			else
				return false;
		}

		public function get_StartMonth()
		{
				return  $this->_get_StartMonthValue();
		}

		private function _get_StartMonthValue()
		{
			if(isset($this->_StartMonth['value']))
				return $this->_StartMonth['value'];
			else
				return false;
		}

		public function get_StartYear()
		{
				return  $this->_get_StartYearValue();
		}

		private function _get_StartYearValue()
		{
			if(isset($this->_StartYear['value']))
				return $this->_StartYear['value'];
			else
				return false;
		}

		public function get_IssueNo()
		{
				return  $this->_get_IssueNoValue();
		}

		private function _get_IssueNoValue()
		{
			if(isset($this->_IssueNo['value']))
				return $this->_IssueNo['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_OrderHeaderValue($strOrderHeader)
		{
			if($this->validateInput("validatexxxxx", $strOrderHeader, "OrderHeader "))
					return($this->_setNewValue($this->_OrderHeader, $strOrderHeader));
			else
					return false;
		}

		public function set_NameValue($strName)
		{
			if($this->validateInput("validatexxxxx", $strName, "Name "))
					return($this->_setNewValue($this->_Name, $strName));
			else
					return false;
		}

		public function set_CardTypeValue($strCardType)
		{
			if($this->validateInput("validatexxxxx", $strCardType, "CardType "))
					return($this->_setNewValue($this->_CardType, $strCardType));
			else
					return false;
		}

		public function set_CardNumberValue($strCardNumber)
		{
			if($this->validateInput("validatexxxxx", $strCardNumber, "CardNumber "))
					return($this->_setNewValue($this->_CardNumber, $strCardNumber));
			else
					return false;
		}

		public function set_ExpiryMonthValue($strExpiryMonth)
		{
			if($this->validateInput("validatexxxxx", $strExpiryMonth, "ExpiryMonth "))
					return($this->_setNewValue($this->_ExpiryMonth, $strExpiryMonth));
			else
					return false;
		}

		public function set_ExpiryYearValue($strExpiryYear)
		{
			if($this->validateInput("validatexxxxx", $strExpiryYear, "ExpiryYear "))
					return($this->_setNewValue($this->_ExpiryYear, $strExpiryYear));
			else
					return false;
		}

		public function set_StartMonthValue($strStartMonth)
		{
			if($this->validateInput("validatexxxxx", $strStartMonth, "StartMonth "))
					return($this->_setNewValue($this->_StartMonth, $strStartMonth));
			else
					return false;
		}

		public function set_StartYearValue($strStartYear)
		{
			if($this->validateInput("validatexxxxx", $strStartYear, "StartYear "))
					return($this->_setNewValue($this->_StartYear, $strStartYear));
			else
					return false;
		}

		public function set_IssueNoValue($strIssueNo)
		{
			if($this->validateInput("validatexxxxx", $strIssueNo, "IssueNo "))
					return($this->_setNewValue($this->_IssueNo, $strIssueNo));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblCardDetails
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_OrderHeader['updated'])
					{
						$strSql .= $strJoin." OrderHeader = '".$this->_OrderHeader['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_OrderHeader['oldvalue']."' to '".$this->_OrderHeader['value']."'<br/>";
						$strErrorMsg .= "OrderHeader not updated<br/>";					}

					if($this->_Name['updated'])
					{
						$strSql .= $strJoin." Name = '".$this->_Name['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Name['oldvalue']."' to '".$this->_Name['value']."'<br/>";
						$strErrorMsg .= "Name not updated<br/>";					}

					if($this->_CardType['updated'])
					{
						$strSql .= $strJoin." CardType = '".$this->_CardType['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_CardType['oldvalue']."' to '".$this->_CardType['value']."'<br/>";
						$strErrorMsg .= "CardType not updated<br/>";					}

					if($this->_CardNumber['updated'])
					{
						$strSql .= $strJoin." CardNumber = '".$this->_CardNumber['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_CardNumber['oldvalue']."' to '".$this->_CardNumber['value']."'<br/>";
						$strErrorMsg .= "CardNumber not updated<br/>";					}

					if($this->_ExpiryMonth['updated'])
					{
						$strSql .= $strJoin." ExpiryMonth = '".$this->_ExpiryMonth['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ExpiryMonth['oldvalue']."' to '".$this->_ExpiryMonth['value']."'<br/>";
						$strErrorMsg .= "ExpiryMonth not updated<br/>";					}

					if($this->_ExpiryYear['updated'])
					{
						$strSql .= $strJoin." ExpiryYear = '".$this->_ExpiryYear['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ExpiryYear['oldvalue']."' to '".$this->_ExpiryYear['value']."'<br/>";
						$strErrorMsg .= "ExpiryYear not updated<br/>";					}

					if($this->_StartMonth['updated'])
					{
						$strSql .= $strJoin." StartMonth = '".$this->_StartMonth['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_StartMonth['oldvalue']."' to '".$this->_StartMonth['value']."'<br/>";
						$strErrorMsg .= "StartMonth not updated<br/>";					}

					if($this->_StartYear['updated'])
					{
						$strSql .= $strJoin." StartYear = '".$this->_StartYear['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_StartYear['oldvalue']."' to '".$this->_StartYear['value']."'<br/>";
						$strErrorMsg .= "StartYear not updated<br/>";					}

					if($this->_IssueNo['updated'])
					{
						$strSql .= $strJoin." IssueNo = '".$this->_IssueNo['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_IssueNo['oldvalue']."' to '".$this->_IssueNo['value']."'<br/>";
						$strErrorMsg .= "IssueNo not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblCardDetails()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblCardDetails
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblCardDetails = new MySqlResults($strSql);
		
				if(!$qryDeletetblCardDetails->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblCardDetails()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblCardDetails
						  (
		 	OrderHeader

		, 	Name

		, 	CardType

		, 	CardNumber

		, 	ExpiryMonth

		, 	ExpiryYear

		, 	StartMonth

		, 	StartYear

		, 	IssueNo
)VALUE(
		 	$this->get_OrderHeaderValue() 
		, 	$this->get_NameValue() 
		, 	$this->get_CardTypeValue() 
		, 	$this->get_CardNumberValue() 
		, 	$this->get_ExpiryMonthValue() 
		, 	$this->get_ExpiryYearValue() 
		, 	$this->get_StartMonthValue() 
		, 	$this->get_StartYearValue() 
		, 	$this->get_IssueNoValue() 
			)";
			
			$qryInserttblCardDetails = new MySqlResults($strSql);
		if ($qryInserttblCardDetails->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblCardDetails");
			
		return true;
	}
	}

?>